package com.newtouch.bxzs.business.personal.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.newtouch.bxzs.business.config.MyLog;
import com.newtouch.bxzs.business.personal.model.CommonProblemBO;
import com.newtouch.bxzs.business.personal.model.CommonProblemVO;
import com.newtouch.bxzs.business.personal.model.EnableCommonProblemVO;
import com.newtouch.bxzs.business.personal.model.ModifyCommonProblemVO;
import com.newtouch.bxzs.business.personal.service.CommonProblemService;
import com.newtouch.bxzs.common.base.response.BaseResponse;
import com.newtouch.bxzs.common.base.response.RespGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 常见问题控制器
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2020年12月31日</td>
 * <td>xiongdianqiang</td>
 * <td>Create</td>
 * </tr>
 * </table>
 * 
 * @author xiongdianqiang
 * 
 * @version 1.0.0
 * @since 1.0.0
 */
@RestController
@Api(tags = "维护常见问题")
@SuppressWarnings("unchecked")
@RequestMapping(value = "/commonProblemController")
public class CommonProblemController {

	/** 静态变量：系统日志 */
	private static final Log logger = LogFactory.getLog(CommonProblemController.class);

	@Autowired
	private CommonProblemService commonProblemsService;

	@ApiOperation("获取常见问题列表（pc/app）")
	@PostMapping(value = "/getCommonProblemList")
	@MyLog(systemFunctionName = "维护常见问题", systemFunctionUrl = "/commonProblemController/getCommonProblemList", userOperationType = 4, userOperationSummary = "获取常见问题列表")
	public BaseResponse<Map<String, Page<CommonProblemBO>>> getCommonProblemList(
			@RequestBody CommonProblemVO commonProblemVO) {
		logger.info("获取常见问题列表");
		Map<String, Page<CommonProblemBO>> commonProblemList = commonProblemsService
				.getCommonProblemList(commonProblemVO);
		return RespGenerator.returnOK(commonProblemList);
	}

	@GetMapping(value = "/getCommonProblemDetail")
	@ApiOperation("获取常见问题详情")
	@ApiImplicitParam(name = "problemCommonId", value = "常见问题id", required = true, paramType = "query", dataType = "String")
	@MyLog(systemFunctionName = "维护常见问题", systemFunctionUrl = "/commonProblemController/getCommonProblemDetail", userOperationType = 4, userOperationSummary = "获取常见问题详情")
	public BaseResponse<CommonProblemBO> getCommonProblemDetail(
			@RequestParam(value = "problemCommonId") String problemCommonId) {
		logger.info("获取问题反馈详情");
		return RespGenerator.returnOK(commonProblemsService.getCommonProblemDetail(problemCommonId));
	}

	@PostMapping(value = "/modifyCommonProblem")
	@ApiOperation("新增或者修改常见问题")
	@MyLog(systemFunctionName = "维护常见问题", systemFunctionUrl = "/commonProblemController/modifyCommonProblem", userOperationType = 5, userOperationSummary = "新增或者修改常见问题")
	public BaseResponse<String> modifyCommonProblem(@RequestBody ModifyCommonProblemVO modifyCommonProblemVO) {
		logger.info("修改或新增常见问题");
		return RespGenerator.returnOK(commonProblemsService.modifyCommonProblem(modifyCommonProblemVO));
	}

	@PostMapping(value = "/deleteCommonProblem")
	@ApiOperation("删除常见问题")
	@MyLog(systemFunctionName = "维护常见问题", systemFunctionUrl = "/commonProblemController/deleteCommonProblem", userOperationType = 3, userOperationSummary = "删除常见问题")
	public BaseResponse<String> deleteCommonProblem(
			@RequestBody @ApiParam(name = "problemCommonIds", value = "常见问题id集合", required = true) List<String> problemCommonIds) {
		logger.info("删除常见问题");
		commonProblemsService.deleteCommonProblem(problemCommonIds);
		return RespGenerator.returnOK("成功");
	}

	@PostMapping(value = "/enableCommonProblem")
	@ApiOperation("发布/撤销常见问题")
	@MyLog(systemFunctionName = "维护常见问题", systemFunctionUrl = "/commonProblemController/enableCommonProblem", userOperationType = 2, userOperationSummary = "发布/撤销常见问题")
	public BaseResponse<String> enableCommonProblem(@RequestBody EnableCommonProblemVO enableCommonProblemVO) {
		logger.info("发布/撤销常见问题");
		commonProblemsService.enableCommonProblem(enableCommonProblemVO);
		return RespGenerator.returnOK("成功！");
	}
}
